package com.example.administrator.shzs.parse;


import com.example.administrator.shzs.entity.IndexCarousel;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/** 首页轮播图
 * Created by lanouhn on 2016/8/29.
 */
public class ParseIndexCarousel {

    public static List<IndexCarousel> getIndexCarousel(String json) {

        List<IndexCarousel> list = new ArrayList<>();

        try {
            JSONObject jsonObject = new JSONObject(json);
            JSONArray array = jsonObject.optJSONArray("foodtypelist");

            if (null != array && array.length() > 0) {

                for (int i = 0; i < array.length(); i++) {
                    JSONObject obj = array.getJSONObject(i);
                    IndexCarousel indexCarousel = new IndexCarousel();
                    indexCarousel.setSortName(obj.getString("SortName"));
                    list.add(indexCarousel);
                }
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return list;
    }
}
